package com.sixth.controller;

import com.sixth.bean.MarketUser;
import com.sixth.bean.bo.WxCollectAddOrDeleteBo;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BasePageInfoVo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.common.BaseResultVo;
import com.sixth.constant.Constant;
import com.sixth.service.WxCollectService;
import com.sixth.util.MarketInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName WxCollectController
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/11 13:23
 **/

@RestController
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    WxCollectService wxCollectService;

    /**
     * @Param
     * @Return
     * @author XiaoWJ
     * @date 2022/9/11 13:28
     */

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo, Integer type) {
        MarketUser marketUser = MarketInfoUtil.getMarketUser();

        Object result = wxCollectService.list(basePageInfo, type, marketUser.getId());

        return BaseRespVo.ok(result);

    }

    /**
     * @Param
     * @Return
     * @author XiaoWJ
     * @date 2022/9/11 13:28
     */

    @RequestMapping("addordelete")
    public BaseResultVo addordelete(@RequestBody WxCollectAddOrDeleteBo wxCollectAddOrDeleteBo) {
        MarketUser marketUser = MarketInfoUtil.getMarketUser();

        // 如果用户没有登录，直接返回成功
        if(marketUser == null) {
            return BaseResultVo.ok();
        }
        int code = wxCollectService.addOrDelete(wxCollectAddOrDeleteBo.getType(), wxCollectAddOrDeleteBo.getValueId(), marketUser.getId());

        if (code == Constant.OK) {
            return BaseResultVo.ok();
        }
        return BaseResultVo.error("失败");
    }


}
